package cn.arnold.offer.jiaohang;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Arnold-Xiang
 * @Info 判断一个数是不是质数
 */
public class Solution {
    public static void main(String[] args) {
        Integer[] nums = new Integer[]{3, 5, 11, 12};
        Integer[] prime = findPrime(nums);
        for (int i = 0; i < prime.length; i++) {
            System.out.println(prime[i]);
        }
    }

    public static Integer[] findPrime(Integer[] nums) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            boolean flag = true;
            for (int j = 2; j <= num / 2; j++) {
                if (num % j == 0) {
                    //不是质数
                    flag = false;
                }
            }
            if (flag == true) {
                list.add(num);
            }
        }
        Integer[] res = new Integer[list.size()];
        return list.toArray(res);
    }
}
